/**
  ******************************************************************************
  * @file           : XYXKC_Serial_ml307r.cpp
  * @author         : admin
  * @brief          : None
  * @attention      : None
  * @date           : 2024/11/24
  ******************************************************************************
  */

#include "XYXKC_Serial_ml307r.h"

XYXKC_Serial_ml307r::XYXKC_Serial_ml307r(){}
XYXKC_Serial_ml307r::~XYXKC_Serial_ml307r(){}

void XYXKC_Serial_ml307r::begin(SoftwareSerial *serial, int baudRate) {
    _isHardware = false;
    _hardware = NULL;
    _software = serial;
    _software->begin(baudRate);
}
void XYXKC_Serial_ml307r::begin(HardwareSerial *serial,int baudRate) {
    _isHardware = true;
    _software = NULL;
    _hardware = serial;
    _hardware->begin(baudRate);
}
void XYXKC_Serial_ml307r::begin(HardwareSerial *serial, int rx, int tx,int baudRate) {
    _isHardware = true;
    _hardware = serial;
    _hardware->begin(baudRate,rx, tx);
}

void XYXKC_Serial_ml307r::end() {
    _isHardware? _hardware->end() : _software->end();
}
int XYXKC_Serial_ml307r::read() {
    return _isHardware?_hardware->read():_software->read();

}

int XYXKC_Serial_ml307r::available() {
    return _isHardware?_hardware->available():_software->available();
}
size_t XYXKC_Serial_ml307r::write(uint8_t byte){
    return _isHardware?_hardware->write(byte):_software->write(byte);
}
String XYXKC_Serial_ml307r::readString(){
    return _isHardware?_hardware->readString():_software->readString();
}

size_t XYXKC_Serial_ml307r::readBytes(char *buffer,size_t  length){
    return _isHardware?_hardware->readBytes(buffer,length):_software->readBytes(buffer,length);
}
size_t XYXKC_Serial_ml307r::readBytesUntil(char terminator, char *buffer, size_t length){
    return _isHardware?_hardware->readBytesUntil(terminator,buffer,length):_software->readBytesUntil(terminator,buffer,length);
}
String XYXKC_Serial_ml307r::readStringUntil(char terminator){
    return _isHardware?_hardware->readStringUntil(terminator):_software->readStringUntil(terminator);
}
void XYXKC_Serial_ml307r::flush(){
    _isHardware?_hardware->flush():_software->flush();
}